<template>
    <div class="goods-pingjia">
        <div class="goods-pingjia-card">
            <Row :gutter="10">
                <Col span="6">
                    <DatePicker  clearable v-model="searchData.timeStartEnd" style="width: 100%" type="daterange" placeholder="时间筛选"></DatePicker>
                </Col>
                <Col span="6">
                    <Input clearable v-model="searchData.goodsName" placeholder="商品名称" type="text"></Input>
                </Col>
                <Col span="6">
                    <Input clearable v-model="searchData.order" placeholder="订单号" type="text"></Input>
                </Col>
                <Col span="6">
                    <Input clearable v-model="searchData.shopName" placeholder="店铺名称" type="text"></Input>
                </Col>
            </Row>
            <Row :gutter="10" style="padding: 10px 0;">
                <Col span="5">
                    <Input clearable v-model="searchData.userName" placeholder="用户名" type="text"></Input>
                </Col>
                <Col span="5">
                    <Input clearable v-model="searchData.content" placeholder="评价内容" type="text"></Input>
                </Col>
                <Col span="5">
                    <Select clearable v-model="searchData.isTimeUp" placeholder="创建时间排序">
                        <Option :value="1">升序</Option>
                        <Option :value="2">降序</Option>
                    </Select>
                </Col>
                <Col span="5">
                <Select clearable v-model="searchData.isShow" placeholder="选择隐藏显示">
                    <Option :value="-1">隐藏</Option>
                    <Option :value="1">显示</Option>
                </Select>
                </Col>
                <Col span="4">
                    <Button style="float: right" :loading="search_loading" @click="searchGetList" type="primary">
                        <Icon type="ios-pulse-strong"></Icon> 筛 选
                    </Button>
                </Col>
            </Row>
            <i-table height="640" stripe :columns="columns" :data="data"></i-table>
            <div style="padding: 15px;">
                <Page @on-page-size-change="changeTiao" @on-change="changePage" :current="index" :total="total" show-elevator show-sizer :placement="'top'" :page-size="page_con" :page-size-opts="[10, 15, 20, 30, 40, 50]"></Page>
            </div>
        </div>
        <Modal v-model="modal2" width="360">
            <p slot="header" style="color:#f60;text-align:center">
                <Icon type="information-circled"></Icon>
                <span>删除确认</span>
            </p>
            <div style="text-align:center">
                <p>是否继续删除？</p>
            </div>
            <div slot="footer">
                <Button type="error" size="large" long :loading="modal_loading" @click="del">删除</Button>
            </div>
        </Modal>
    </div>
</template>
<script>
    export default {
        name:"goods-pingjia",
        data(){
            return{
                columns:[
                    {
                        title: '序号',
                        type: 'index',
                        width: 60,
                        align:"center",
                    },
                    {
                        title: '商品图标',
                        key: 'goodsimg',
                        align:"center",
                        width:100,
                        render:(h,params)=>{
                            if(params.row.goodsimg==""){
                                return "暂无"
                            }else{
                                return h("div",{
                                    style:{
                                        cursor: "pointer",
                                    },
                                    on:{
                                        mouseover:(e)=>{
                                            this.$store.commit("setImgData",{
                                                src:e.target.src||e.target.getElementsByTagName("img")[0].src||"",
                                                x:e.x+50+"px",
                                                y:e.y-60+"px",
                                            })
                                        },
                                        mousemove:(e)=>{
                                            this.$store.commit("setImgData",{
                                                src:e.target.src||e.target.getElementsByTagName("img")[0].src||"",
                                                x:e.x+50+"px",
                                                y:e.y-60+"px",
                                            })
                                        },
                                        mouseout:(e)=>{
                                            this.$store.commit("setImgData",{
                                                src:"",
                                                x:"0px",
                                                y:"0px",
                                            })
                                        }
                                    }
                                },[
                                    h("img",
                                        {
                                            attrs:{
                                                src:params.row.goodsimg
                                            },
                                            style:{
                                                width:"42px",
                                                height:"42px",
                                                borderRadius:"4px",
                                                margin:"0px auto",
                                                display:"block",
                                            },
                                        })
                                ])
                            }
                        }
                    },
                    {
                        title: '商品名称',
                        key: 'goodsname',
                        align:"center",
                        width:300,
                        render:(h,params)=>{
                            return h("Tooltip",{
                                props:{
                                    placement:"top-start",
                                }
                            },[
                                h("span",{
                                    attrs:{
                                        "class":"notwrap"
                                    },
                                    style:{
                                        cursor:"pointer",
                                        width:"100%",
                                    }
                                },params.row.goodsname),
                                h("div",{
                                    slot:"content",
                                    style:{
                                        "white-space":"normal"
                                    }
                                },params.row.goodsname+"")
                            ])
                        }
                    },
                    {
                        title: '订单号',
                        key: 'orderno',
                        width:130,
                        align:"center",
                    },
                    {
                        title: '状态',
                        key: 'isshow',
                        align:"center",
                        width:100,
                        render:(h,params)=>{
                            return h("div",
                                [
                                    h("Icon",{
                                        props:{type: params.row.isshow==1?'eye':'eye-disabled'}
                                    }),
                                    h("span",params.row.isshow==1?' 显示':' 隐藏')
                                ]
                            )
                        }
                    },
                    {
                        title: '评价内容',
                        key: 'content',
                        align:"center",
                        width:320,
                        render:(h,params)=>{
                            return h("Tooltip",{
                                props:{
                                    placement:"top-start",
                                }
                            },[
                                h("span",{
                                    attrs:{
                                        "class":"notwrap"
                                    },
                                    style:{
                                        cursor:"pointer",
                                        width:"100%",
                                    }
                                },"[ "+params.row.username+' ] : '+params.row.content),
                                h("div",{
                                    slot:"content",
                                    style:{
                                        "white-space":"normal"
                                    }
                                },"[ "+params.row.username+' ] : '+params.row.content+"")
                            ])
                        }
                    },
                    {
                        title: '商品评分',
                        key: 'goodsscore',
                        align:"center",
                        render:(h,params)=>{
                            let array=[]
                            for(let i=0;i<parseInt(params.row.goodsscore);i++){
                                array.push(
                                    h("Icon",{
                                        props:{
                                            type:"android-star",
                                            size:20,
                                            color:"#ff5b00"
                                        }
                                    })
                                )
                            }
                            for(let i=0;i<5-parseInt(params.row.goodsscore);i++){
                                array.push(
                                    h("Icon",{
                                        props:{
                                            type:"android-star",
                                            size:20,
                                            color:"#c3c3c3"
                                        }
                                    })
                                )
                            }
                           return h("span",
                               array
                           )
                        }
                    },
                    {
                        title: '时效评分',
                        key: 'timescore',
                        align:"center",
                        render:(h,params)=>{
                            let array=[]
                            for(let i=0;i<parseInt(params.row.timescore);i++){
                                array.push(
                                    h("Icon",{
                                        props:{
                                            type:"android-star",
                                            size:20,
                                            color:"#ff5b00"
                                        }
                                    })
                                )
                            }
                            for(let i=0;i<5-parseInt(params.row.timescore);i++){
                                array.push(
                                    h("Icon",{
                                        props:{
                                            type:"android-star",
                                            size:20,
                                            color:"#c3c3c3"
                                        }
                                    })
                                )
                            }
                            return h("span",
                                array
                            )
                        }
                    },
                    {
                        title: '服务评分',
                        key: 'servicescore',
                        align:"center",
                        render:(h,params)=>{
                            let array=[]
                            for(let i=0;i<parseInt(params.row.servicescore);i++){
                                array.push(
                                    h("Icon",{
                                        props:{
                                            type:"android-star",
                                            size:20,
                                            color:"#ff5b00"
                                        }
                                    })
                                )
                            }
                            for(let i=0;i<5-parseInt(params.row.servicescore);i++){
                                array.push(
                                    h("Icon",{
                                        props:{
                                            type:"android-star",
                                            size:20,
                                            color:"#c3c3c3"
                                        }
                                    })
                                )
                            }
                            return h("span",
                                array
                            )
                        }
                    },
                    {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        render: (h, params) => {
                            return h('ButtonGroup', [
                                h('Button', {
                                    props: {
                                        type: 'warning',
                                    },
                                    on: {
                                        click: () => {
                                            this.tiao(params.index)
                                        }
                                    }
                                },"修改"),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.index)
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    },
                ],
                data:[],
                total:0,
                index:1,
                page_con:15,
                searchData:{
                    timeStartEnd:[],//两个时间内的赛选
                    isTimeUp:"",//时间排序
                    goodsName:"",//商品名称
                    shopName:"",//店铺名称
                    order:"",//订单号
                    userName:"",//用户名
                    content:"",//评价内容
                    isShow:"",//是否显示
                },
                search_loading:false,
                modal2:false,
                doIndex:0,//操作的下标
                modal_loading:false,
            }
        },
        activated(){
            this.getGoodsPingjiaList()
        },
        methods:{
            getGoodsPingjiaList(){
                this.getJsonData("Appraises/getAllAppraises",{
                    num:this.page_con,
                    page:this.index,
                    begin:this.searchData.timeStartEnd[0]?this.searchData.timeStartEnd[0]/1000:"",
                    last:this.searchData.timeStartEnd[1]?this.searchData.timeStartEnd[1]/1000:"",
                    goodsName:this.searchData.goodsName,
                    shopName:this.searchData.shopName,
                    sort:this.searchData.isTimeUp,
                    username:this.searchData.userName,
                    orderNum:this.searchData.order,
                    isShow:this.searchData.isShow,
                    content:this.searchData.content,
                },true)
                    .then((res) => {
                        this.search_loading=false
                        this.data=res.data
                        this.total=parseInt(res.count)
                    })
                    .catch((res)=>{
                        this.search_loading=false
                    })
            },
            changePage(n){
                this.index=n
                this.getGoodsPingjiaList()
            },
            changeTiao(num){
                this.page_con=num
                this.index=1
                this.getGoodsPingjiaList()
            },
            searchGetList(){
                this.search_loading=true
                this.getGoodsPingjiaList()
                this.index=1
            },
            remove(n){
                this.doIndex=n
                this.modal2=true
            },
            del(){
                this.modal_loading = true;
                this.getJsonData("Appraises/deleteAppraises",{id:this.data[this.doIndex].id},true)
                    .then((res)=>{
                        this.getGoodsPingjiaList()
                        this.modal_loading = false;
                        this.modal2 = false;
                        this.$Message.success('删除成功');
                    }).catch((res)=>{
                    this.modal_loading = false;
                    this.modal2 = false;
                })
            },
            tiao(n){
                this.$router.push({name:"goods-pingjia-edit-nocache",query:{id:this.data[n].id}})
            }
        }
    }
</script>
<style lang="less">
    @import "./goods-pingjia";
</style>